import { Component } from '@angular/core';
import { Platform } from 'ionic-angular';
import { StatusBar } from '@ionic-native/status-bar';
import { SplashScreen } from '@ionic-native/splash-screen';
import { ValidateProvider } from "../providers/validate/validate";
import { UrlProvider } from "../providers/url/url";
import { StorageProvider } from "../providers/storage/storage";

@Component({
    templateUrl: 'app.html'
})
export class MyApp {
    rootPage: any;
    constructor(platform: Platform, statusBar: StatusBar, splashScreen: SplashScreen, validate: ValidateProvider, url: UrlProvider, storage: StorageProvider) {
        
        platform.ready().then(() => {
            if (location.href.indexOf('&') != -1) {
                location.href = location.href.replace(/&/g, "@");
            } else {
                // Okay, so the platform is ready and our plugins are available.
                // Here you can do any higher level native things you might need.
                statusBar.styleDefault();
                splashScreen.hide();
                if (url.getParam('share_token') && url.getParam('page')) {
                    let shareData = {
                        token: url.getParam('share_token'),
                        page: url.getParam('page'),
                        data: url.getParam('data') ? JSON.parse(decodeURI(url.getParam('data'))) : ''
                    };
                    storage.set('shareData', JSON.stringify(shareData));
                }

                if (!validate.checkLogin()) {
                    this.rootPage = 'LoginPage';
                } else {
                    this.rootPage = 'HomePage';
                }
            }

        });

    }


}